package transactionimplementation

import (
	"fmt"
	"log"
	"reflect"
	"salary/database"
	"salary/modelimplementation"
	"strconv"
	"time"
)

type SalesReceiptTransaction struct {
	empid     int
	salesDate time.Time
	amount    float64
}

func (srt *SalesReceiptTransaction) Execute() {
	e := database.Database.GetEmployee(srt.empid)
	if e != nil {
		pc := e.GetClassification()
		if reflect.TypeOf(pc) == reflect.TypeOf(modelimplementation.CommissionClassification{}) {
			cc := pc.(*modelimplementation.CommissionClassification)
			sr := modelimplementation.NewSalesReceipt(srt.salesDate, srt.amount)
			cc.AddSalesReceipt(*sr)
		} else {
			log.Println(fmt.Errorf(database.ExceptionMessage.NotCommissionedClassification +
				strconv.Itoa(e.GetEmpid())))
		}
	} else {
		log.Println(fmt.Errorf(database.ExceptionMessage.EmployeeNotExist + strconv.Itoa(e.GetEmpid())))
	}
}

